<?php

require('config.php');

$page = new rootLayoutPrint();
$translate = tmxTranslate('place_detail.xml', REP_XLAT_TEMPLATE);
$tpl_file='print.tpl';
$print = new flyLayout(REP_TPL . $tpl_file);
$print->start();

$language_link=$_GET['id'];
$location = modelLocationMap::getList($language_link,1,2);//$status =2,3,6 
	if($location){
		$page->setBaliseTitle($language_link);
			if($location->comment<>'' and $location->status==LOCATION_REFUSE){
				$print->setVariable('comment', nl2br($location->comment));
				$print->showBlock('user_comment');
			}
			$print->setVariable('place_name',($location->name_place));
			
			
			/*if($location->content!=''){
				$print->setVariable('full_description', nl2br($location->content));
				$print->showBlock('show_full_description');
			}*/
			
			if($location->content!=''){
			$print->setVariable('full_description', nl2br($location->content));
			$print->showBlock('show_full_description');
		}else{
			$content = '';
			$listKeyword = modelKeyWord::getKeywordByIDLocation($location->language_link,1);
			if($listKeyword->size() > 0){
				foreach($listKeyword as $k => $key1){
					$br = $key1->id_key==0?'. <br />':', ';
					$content .= $key1->title.$br.' ';
				}
				$content = preg_replace('!,([\s]*)\.!iUs', '.', $content);
				$content = substr(trim($content),0,-1);
				$content__ = '';
				$content = split('. <br />',$content);
				$count = count($content);
				for($x = 0;  $x < $count; $x++){
					$content_ = trim($content[$x]);
					if($x==$count-1){
						if($_SESSION['language_code']=='kh'){
							$content__ .= $content_.'.<br />';
						}else{
							$content__ .= strtoupper(substr($content_,0,1)).(substr($content_,1));
						}
					}else{
						if($_SESSION['language_code']=='kh'){
							$content__ .= $content_.'.<br />';
						}else{
							$content__ .= strtoupper(substr($content_,0,1)).(substr($content_,1)).'.<br />';
						}
					}
				}
			$print->setVariable('full_description', nl2br($content__));
			$print->showBlock('show_full_description');
			}
		}

			if($location->zip_code!=''){
				$print->setVariable('zip_code', ($location->zip_code));
				$print->showBlock('show_zip_code');
			}
			if($location->reference!=''){
				$print->setVariable('reference', ($location->reference));
				$print->showBlock('show_reference');
			}

			$all_price = modelMap::getPrice($location->id_map_address_price);
			if($all_price->price_rental<>0){
				$print->setVariable('price_rental', number_format($all_price->price_rental,0,'.',' ').' '.CURRENCY);
				$print->showBlock('price_rental');
			}

			if($location->length<>0){
				$print->setVariable('length', $location->length);
				$print->showBlock('length');
			}
			if($location->width<>0){
				$print->setVariable('width', $location->width);
				$print->showBlock('width');
			}
			if($location->height<>0){
				$print->setVariable('height', $location->height);
				$print->showBlock('height');
			}
			if($all_price->price_sell<>0){
				$print->setVariable('price_sell', number_format($all_price->price_sell,0,'.',' ').' '.CURRENCY);
				$print->showBlock('price_sell');
			}
			if($location->size_building<>0){
				$print->setVariable('size_building', $location->size_building);
				$print->showBlock('size_building');
			}
			if($location->length_land<>0){
				$print->setVariable('length_land', $location->length_land);
				$print->showBlock('length_land');
			}
			if($location->width_land<>0){
				$print->setVariable('width_land', $location->width_land);
				$print->showBlock('width_land');
			}
			if($location->size_land<>0){
				$print->setVariable('size_land', $location->size_land);
				$print->showBlock('size_land');
			}
			if($location->bedrooms<>0){
				$print->setVariable('bedroom', $location->bedrooms);
				$print->showBlock('bedroom');
			}
			if($location->bathrooms<>0){
				$print->setVariable('bathroom', $location->bathrooms);
				$print->showBlock('bathroom');
			}
			if($location->mezzanine){
				//$print->setVariable('mezzanine', $location->mezzanine?YES:NO);
				$print->showBlock('mezzanine');
			}
			if($location->furnished_apartment){
				//$print->setVariable('furnished_apartment', $location->furnished_apartment?YES:NO);
				$print->showBlock('furnished_apartment');
			}

			if($location->furnished_detail!=''){
				$print->setVariable('furnished_detail', nl2br($location->furnished_detail));
				$print->showBlock('furnished_detail');
			}
			if($location->floor<>0){
				$print->setVariable('floor', $location->floor);
				$print->showBlock('floor');
			}
			if($location->number_floor<>0){
				$print->setVariable('number_floor', $location->number_floor);
				$print->showBlock('number_floor');
			}
			if($location->tenant){
				//$print->setVariable('tenant', $location->tenant?YES:NO);
				$print->showBlock('tenant');
			}

			if($location->end_tenant>0){
				$print->setVariable('end_tenant', affiche($location->end_tenant,'date'));
				$print->showBlock('end_tenant');
			}


			$format = modelUploadFormat::getObject(FORMAT_PREVIEW_PHOTO);
			$listPhotos_out = modelPhoto::getListPhotoLocation_out($location->language_link);

			if($listPhotos_out->size() > 0) {
				foreach($listPhotos_out as $key => $fichier) {
					$url_image = $fichier->url_repertoire.$format->url_format.$fichier->nom_serveur;

					if(file_exists($url_image)){
						$print->setVariable('url_profil_photo_no_session', $url_image);
					}else{
						$print->setVariable('url_profil_photo_no_session', NOIMAGE);
					}
					$print->parseList('list_photo_no_session');
				}

			}
			$listKeyword = modelKeyWord::getKeywordByIDLocation($location->language_link);
			if($listKeyword->size() > 0){
				foreach($listKeyword as $k => $key1){
					if($k < ($listKeyword->size()/2)){
						$print->setVariable('url_k1',$key1->url_rewriting.'-'.$key1->language_link.'.html');
						$print->setVariable('title_k1',$key1->meta_title);
						$print->setVariable('k1',$key1->title);
						$print->parseList('keyword1');
					}
					else{
						$print->setVariable('url_k2',$key1->url_rewriting.'-'.$key1->language_link.'.html');
						$print->setVariable('title_k2',$key1->meta_title);
						$print->setVariable('k2',$key1->title);
						$print->parseList('keyword2');
					}
				}

				$print->showBlock("keyword_location");
			}
			$print->showBlock("have_value");
	}else  $print->showBlock("no_value");

$print->setVariable('label_3', $translate['label_3']);
$print->setVariable('label_2', $translate['label_2']);
$print->setVariable('label_6', $translate['label_6']);
$print->setVariable('label_8', $translate['label_8']);
$print->setVariable('label_26', $translate['label_26']);
$print->setVariable('label_10', $translate['label_10']);
$print->setVariable('label_11', $translate['label_11']);
$print->setVariable('label_27', $translate['label_27']);
$print->setVariable('label_23', $translate['label_23']);
$print->setVariable('label_28', $translate['label_28']);
$print->setVariable('label_29', $translate['label_29']);
$print->setVariable('label_30', $translate['label_30']);
$print->setVariable('label_31', $translate['label_31']);
$print->setVariable('label_32', $translate['label_32']);
$print->setVariable('label_12', $translate['label_12']);
$print->setVariable('label_13', $translate['label_13']);
$print->setVariable('label_14', $translate['label_14']);
$print->setVariable('label_15', $translate['label_15']);
$print->setVariable('label_16', $translate['label_16']);
$print->setVariable('label_17', $translate['label_17']);
$print->setVariable('label_18', $translate['label_18']);
$print->setVariable('text_20', $translate['text_20']);

$print->stop();
$page->setBody($print);
$page->display();

?>